#include "../s21_decimal.h"

int s21_compare(s21_decimal *value_1, s21_decimal *value_2) {
  int result = 0;

  if (s21_is_valid(value_1) && s21_is_valid(value_2)) {
    s21_long_decimal first = INIT_ZERO_S21_LONG_DECIMAL;
    s21_extend(value_1, &first);
    s21_long_decimal second = INIT_ZERO_S21_LONG_DECIMAL;
    s21_extend(value_2, &second);
    int first_sign = s21_get_long_sign(&first);
    int second_sign = s21_get_long_sign(&second);

    if (s21_is_long_zero(&first) && s21_is_long_zero(&second)) {
      result = 0;
    } else if (first_sign == NEGATIVE && second_sign == POSITIVE) {
      result = -1;
    } else if (first_sign == POSITIVE && second_sign == NEGATIVE) {
      result = 1;
    } else {  // first_sign == second_sign
      s21_equalize_long_scale(&first, &second);
      result = s21_compare_only_long_bits(&first, &second);

      if (first_sign == NEGATIVE) {
        result *= -1;
      }
    }
  }

  return result;
}